<template>
  <div class="apply-agreement">
    <loading v-if="loading"></loading>
    <div v-else>
      <div class="content" v-html="agreement.agreement"></div>
      <div class="submit" v-if="showBtn">
        <van-button type="info" size="large" @click="goToAgentApply">同意</van-button>
      </div>
    </div>
  </div>
</template>

<script>
import { Button } from "vant";
import http from "../service/myHttp.js";
import urls from "../service/url.js";
import { mapState } from "vuex";
import loading from "../components/loading.vue";

export default {
  components: {
    vanButton: Button,
    loading
  },
  data() {
    return {
      loading: true,
      agreement: "",
      codeId: this.$route.query.codeId,
      showBtn: this.$route.query.showBtn || 1
      // levelName: this.$route.query.levelName
    };
  },
  beforeRouteEnter(to, from, next) {
    next(that => {
      // 从综合进入此页面，不显示按钮，其他情况都显示
      if (from.path == "/integration") {
        that.showBtn = false;
      } else {
        that.$store.commit("setNavInfo", {
          showNavbar: false
        });
      }
    });
  },
  async mounted() {
    await http.post(urls.HQXY, {}).then(res => {
      // console.log(res);
      if (res.data.code == 200) {
        this.agreement = res.data.data;
      }
    });

    this.loading = false;
  },
  methods: {
    // 跳转到代理申请页面
    goToAgentApply() {
      this.$router.replace({
        path: "/agent_apply",
        query: {
          codeId: this.codeId
          // levelName: this.levelName
        }
      });
    }
  }
};
</script>

<style scoped>
.content {
  padding: 20px;
  background-color: #fff;
}

.apply-agreement .submit {
  margin-bottom: 50px;
}
</style>